package com.deer.wms.base.system.web.ware;

import com.deer.wms.base.system.dao.ware.CustomerMapper;
import com.deer.wms.base.system.model.ware.Customer;
import com.deer.wms.base.system.model.ware.Customer;
import com.deer.wms.common.annotation.Log;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.enums.BusinessType;
import com.deer.wms.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户 信息操作处理
 * 
 * @author guo
 * @date 2019-06-16
 */
@Controller
@RequestMapping("/system/customer")
public class CustomerController extends BaseController
{
    private String prefix = "system/customer";
	
	@Autowired
	private CustomerMapper customerMapper;

	@GetMapping()
	public String Customer()
	{
	    return prefix + "/customer";
	}
	
	/**
	 * 查询客户列表
	 */
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Customer customer)
	{
		startPage();
        List<Customer> list = customerMapper.selectByExample(customer);
		return getDataTable(list);
	}

	/**
	 * 获取客户名下拉菜单(新增出库单)
	 * @param Customer
	 * @return
	 */
	@RequestMapping("/getCustomerNameList")
	@ResponseBody
	public List<Customer> getCustomerNameList(Customer Customer){
		List<Customer> list = customerMapper.getCustomerNameList(Customer);
		return list;
	}

	/**
	 * 导出客户列表
	 */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Customer Customer)
    {
    	List<Customer> list = customerMapper.selectCustomerList(Customer);
        ExcelUtil<Customer> util = new ExcelUtil<Customer>(Customer.class);
        return util.exportExcel(list, "Customer");
    }
	
	/**
	 * 新增客户
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存客户
	 */
	@Log(title = "客户", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Customer Customer)
	{		
		return toAjax(customerMapper.insertSelective(Customer));
	}

	/**
	 * 修改客户
	 */
	@GetMapping("/edit/{CustomerId}")
	public String edit(@PathVariable("CustomerId") Long CustomerId, ModelMap mmap)
	{
		Customer Customer = customerMapper.selectByPrimaryKey(CustomerId);
		mmap.put("customer", Customer);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存客户
	 */
	@Log(title = "客户", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Customer Customer)
	{		
		return toAjax(customerMapper.updateByPrimaryKeySelective(Customer));
	}
	
	/**
	 * 删除客户
	 */
	@Log(title = "客户", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
	return toAjax(customerMapper.deleteByIds(ids));
	}
	
}
